#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
    set<pair<int, string>> temps;
    string temp;
    int n, i, c, j;

    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> c;

        for (j = 0; j < c + 1; j++)
        {
            cin >> temp;
            temps.insert(make_pair(j, temp));
        }
    }

    for (auto p : temps)
    {
        cout << p.second << "\n";
    }
    
    return 0;
}
/* 
7
3 shang yang apple 4
3 shang huang apple 5
3 shang yang banana 3
2 shang orange 4
3 hubei wuhan apple 7
3 hubei wuhan banana 6
2 anhui apple 3
*/